// utils/menu-utils.js

// 扫描所有 views 下的 index.vue 文件
const views = import.meta.glob('@/views/**/index.vue')

export function convertMenusToRoutes(menus) {
  const children = []

  menus.forEach(menu => {
    if (menu.children?.length) {
      menu.children.forEach(child => {
        if (child.path) {
          children.push({
            path: child.path.replace('/app/', ''), // 注意这里
            name: child.name,
            component: () => import(`@/views${child.path.replace('/app', '')}/index.vue`)
          })
        }
      })
    } else if (menu.path) {
      children.push({
        path: menu.path.replace('/app/', ''), // 同样处理
        name: menu.name,
        component: () => import(`@/views${menu.path.replace('/app', '')}/index.vue`)
      })
    }
  })

  return [
    {
      path: '/app',
      component: () => import('@/views/layout/index.vue'),
      redirect: '/app/index',
      children
    }
  ]
}